/*
 * Copyright 2018 Shanxi Lu'an Taihang Laihui Net Tech co.,LTD.
 */
package src.com.bjsxt.height.design015_test;

import java.util.Random;

/**
 * Description:
 *
 * @author wzz
 * @since: 1.0
 * Create Date Time: 2018/10/31 11:19
 * Update Date Time:
 */
public class Main {
    /*public static void main(String[] args) {
        //System.out.println("我的机器可用Processor数量:" + Runtime.getRuntime().availableProcessors());
        Master master = new Master(new Test(),10);
        Random r = new Random();
        for(int i = 1; i <= 100; i++){
            Task t = new Task();
            t.setId(i);
            t.setPrice(r.nextInt(1));
            master.submit(t);
        }
        master.excute();
        long start = System.currentTimeMillis();

        while(true){
            if(master.isComplete()){
                long end = System.currentTimeMillis() - start;
                int priceResult = master.getResult();
                System.out.println("最终结果：" + priceResult + ", 执行时间：" + end);
                break;
            }
        }
    }
*/
    public static void main(String[] args) {
      Master master = new Master(new Work(),10000);
      Random r = new Random();
      for(int i=1;i<=100;i++){
          Task task = new Task();
          task.setId(i);
          task.setPrice(r.nextInt(1000));
          master.submit(task);
      }
      master.excute();
      long start = System.currentTimeMillis();
      while(true){
          if(master.isComplete()){
              long end = System.currentTimeMillis()-start;
              int price = master.getResult();
              System.out.println("最终结果:"+price+",执行时间:"+end);
              break;
          }
      }
    }
}
